package frontend.product.manager;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.Transaction;
import core.product.model.Product;
import core.product.model.ProductType;
import core.util.HibernateCoreUtil;

public class ProductDetailManager  extends HibernateCoreUtil
{
	public List<Product> getSimpleSearchResult(String sku)
	{
		List<Product> lstProd = new ArrayList<Product>();
		Session session = HibernateCoreUtil.getSessionFactory().openSession();
		Transaction transaction = null;
		ProductType pt = null ;
		try 
		{	
				
				transaction = session.beginTransaction();
				//from Category c where c.name='"+name+"' and c.path='"+path+"'")
				Iterator<ProductType> psiItr = session.createQuery("from Product p where p.sku='"+sku+"'").list().iterator();
				while(psiItr.hasNext())
				{
					pt = psiItr.next() ;
					pt.getProductType();
					//lstProd.add(pt.getProductType());
				}
				transaction.commit();
		}
		catch (HibernateException e) 
		{
			// TODO: handle exception
			transaction.rollback();
			e.printStackTrace();
		}
		finally 
		{
			session.close();
		}
		return lstProd;
	}
}
